import { defineStore } from 'pinia';
import { ref } from 'vue';
// 引入获取个人成绩详情信息
import { getPersonScoreDetail } from '@/api/assessment/exammanage.js'

// 引入获取试卷详情的接口
import { getTestPaperDetail } from '@/api/assessment/testpapermanage.js'
export const usePaperTestDataStore = defineStore('paperTestData', () => {
  const singleChoiceDetail = ref([])
  const singleChoiceAssessment = ref(0)

  const multipleChoiceDetail = ref([])
  const multipleChoiceAssessment = ref(0)

  const judgeChoiceDetail = ref([])
  const judgeChoiceAssessment = ref(0)

  const fillChoiceDetail = ref([])
  const fillChoiceAssessment = ref(0)

  const discussChoiceDetail = ref([])
  const discussChoiceAssessment = ref(0)

  // 获取个人成绩详情
  async function getPersonScore (scoreId) {
    const res = await getPersonScoreDetail(scoreId)
    // console.log()
    console.log(res)
    singleChoiceDetail.value = JSON.parse(res.data.singleChoiceDetail)
    multipleChoiceDetail.value = JSON.parse(res.data.multipleChoiceDetail).map(item => {
      return {
        ...item,
        rightAnswers: item.rightAnswersMore.split(','),
      }
    })
    judgeChoiceDetail.value = JSON.parse(res.data.judgeChoiceDetail)
    fillChoiceDetail.value = JSON.parse(res.data.fillChoiceDetail).map(item => {
      return {
        ...item,
        giveMarks: null,
        errorMessage: '',
        isErrorMsg: false
      }
    })
    discussChoiceDetail.value = JSON.parse(res.data.discussChoiceDetail).map(item => {
      return {
        ...item,
        giveMarks: null,
        errorMessage: '',
        isErrorMsg: false
      }
    })
    singleChoiceAssessment.value = res.data.singleChoiceAssessment
    multipleChoiceAssessment.value = res.data.multipleChoiceAssessment
    judgeChoiceAssessment.value = res.data.judgeChoiceAssessment
    fillChoiceAssessment.value = res.data.fillChoiceAssessment
    discussChoiceAssessment.value = res.data.discussChoiceAssessment
  }

  const paperTitle = ref('')
  const singleChoiceValue = ref(0)
  const discussChoiceValue = ref(0)
  const multipleChoiceValue = ref(0)
  const judgeChoiceValue = ref(0)
  const fillChoiceValue = ref(0)
  // 获取试卷详情
  async function getTestPaper (paperId) {
    const res = await getTestPaperDetail(paperId)
    // console.log(res)
    paperTitle.value = res.data.paperTitle
    singleChoiceValue.value = res.data.singleChoiceValue
    discussChoiceValue.value = res.data.discussChoiceValue
    multipleChoiceValue.value = res.data.multipleChoiceValue
    judgeChoiceValue.value = res.data.judgeChoiceValue
    fillChoiceValue.value = res.data.fillChoiceValue
  }

  return {
    singleChoiceDetail,
    singleChoiceAssessment,
    multipleChoiceDetail,
    multipleChoiceAssessment,
    judgeChoiceDetail,
    judgeChoiceAssessment,
    fillChoiceDetail,
    fillChoiceAssessment,
    discussChoiceDetail,
    discussChoiceAssessment,
    getPersonScore,
    getTestPaper,
    singleChoiceValue,
    discussChoiceValue,
    multipleChoiceValue,
    judgeChoiceValue,
    fillChoiceValue,
    paperTitle
  }

})